/**
 * 
 */
package se.izenman.ppt;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

/**
 * @author lusta
 *
 */
public class ControlPPTRobot implements ITCPPPTFunctions{

	private Robot robot;
	private String osName;

	/**
	 * 
	 */
	public ControlPPTRobot() {
		try {
			robot = new Robot();
			osName = System.getProperty("os.name");
		} catch (AWTException e) {
		}
	}

	@Override
	public int nextDiapo() {
		this.robot.keyPress(KeyEvent.VK_RIGHT);
		this.robot.keyRelease(KeyEvent.VK_RIGHT);
		return 0;
	}

	@Override
	public int previousDiapo() {
		this.robot.keyPress(KeyEvent.VK_LEFT);
		this.robot.keyRelease(KeyEvent.VK_LEFT);
		return 0;
	}

	@Override
	public int stopDiapo() {
		this.robot.keyPress(KeyEvent.VK_ESCAPE);
		this.robot.keyRelease(KeyEvent.VK_ESCAPE);
		return 0;
	}

	@Override
	public int startDiapo() {
		if (osName.equals("Mac OS X")){
			this.robot.keyPress(KeyEvent.VK_META);
			this.robot.keyPress(KeyEvent.VK_SHIFT);
			this.robot.keyPress(KeyEvent.VK_ENTER);
			this.robot.keyRelease(KeyEvent.VK_ENTER);
			this.robot.keyRelease(KeyEvent.VK_SHIFT);
			this.robot.keyRelease(KeyEvent.VK_META);
		} else {
			this.robot.keyPress(KeyEvent.VK_F5);
			this.robot.keyRelease(KeyEvent.VK_F5);
		}
		return 0;
	}

	@Override
	public int whiteOn() {
		if (osName.equals("Mac OS X")){
			this.robot.keyPress(KeyEvent.VK_Z);
			this.robot.keyRelease(KeyEvent.VK_Z);
		} else {
			this.robot.keyPress(KeyEvent.VK_B);
			this.robot.keyRelease(KeyEvent.VK_B);
		}
		return 0;
	}

	@Override
	public int whiteOff() {
		whiteOn();
		return 0;
	}

}
